package com.example.data;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import com.example.weather.*;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class copydatabase extends Activity {

   // @Override
    private Button button1;
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.copydatabase);
        button1= (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				InputStream is	=getResources().openRawResource(R.raw.weather);
				String dbdir = "/data/data/com.example.weather/databases/";
				File dir = new File(dbdir);
					if(!dir.exists()){
						dir.mkdir();
						
					}
					String dbname=dbdir +"weather";
					File dbfile = new File(dbname);
					try{
							FileOutputStream fos = new FileOutputStream(dbfile);
							byte []bytes = new byte[4000];
							int count =0;
							while((count=is.read(bytes))>0){
								fos.write(bytes);
							}
							is.close();
							fos.close();
					}catch(FileNotFoundException e){
						
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		});
    }


    //@Override
   /* public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }*/
    
}
